import Mock from 'mockjs'

function getList() {
  const json = {code: 200, success: true, msg: '操作成功'};
  const list = [];
  list.push(
    {
      id: '1',
      dbname: 'kettle1',
      ip: '192.168.1.100',
      port: '1511',
      username: 'root',
      password: 'root',
      type: 'MYSQL',
      remarks: 'KETTLE测试库1',
    },
    {
      id: '2',
      dbname: 'kettle2',
      ip: '192.168.1.101',
      port: '1500',
      username: 'root',
      password: 'root',
      type: 'ORACLE',
      remarks: 'KETTLE测试库2',
    },
  );
  json.data = {
    total: 2,
    size: 10,
    current: 1,
    searchCount: true,
    pages: 1,
    records: list,
  };
  return json;
}

function getDetail() {
  const json = {code: 200, success: true, msg: '操作成功'};
  let detail = {
    id: '1',
    dbname: 'kettle1',
    ip: '192.168.1.100',
    port: '1511',
    username: 'root',
    password: 'root',
    type: 'MYSQL',
    remarks: 'KETTLE测试库1',
  };
  json.data = detail;
  return json;
}

function getSelect() {
  const json = {code: 200, success: true, msg: '操作成功'};
  const list = [];
  list.push(
    {
      id: '1',
      dbname: 'kettle1',
      ip: '192.168.1.100',
      port: '1511',
      username: 'root',
      password: 'root',
      type: 'MYSQL',
      remarks: 'KETTLE测试库1',
    },
    {
      id: '2',
      dbname: 'kettle2',
      ip: '192.168.1.101',
      port: '1500',
      username: 'root',
      password: 'root',
      type: 'ORACLE',
      remarks: 'KETTLE测试库2',
    },
  );
  json.data= list;
  return json;
}

export default ({mock}) => {
  if (!mock) return;
  Mock.mock('/api/kettle/data_source/list', 'get', () => {
    return getList();
  })
  Mock.mock('/api/kettle/data_source/select', 'get', () => {
    return getSelect();
  })
  Mock.mock(/\/api\/kettle\/data_source\/\d+/, 'get', () => {
    return getDetail();
  })
}
